package com.example.sqlite.room;

import android.app.Application;

import java.util.List;

public class AddressRepository {
    private AddressDao addressDao;

    public AddressRepository(Application application) {
        addressDao = AddressRoomDatabase.getInstance(application).getAddressDao();
    }

    public void insert(Address address) {
        AddressRoomDatabase.databaseWriteExecutor.execute(() -> {
            addressDao.insert(address);
        });
    }

    public void delete(Address address) {
        AddressRoomDatabase.databaseWriteExecutor.execute(() -> {
            addressDao.delete(address);
        });
    }

    public void update(Address address) {
        AddressRoomDatabase.databaseWriteExecutor.execute(() -> {
            addressDao.update(address);
        });
    }

    public List<Address> getAll() {
        return addressDao.query();
    }

    public Address getByName(String name) {
        return addressDao.findByName(name);
    }
}
